<template>
  <div class="app-container">
    <eHeader :param-bean="paramBean" :sup_this="sup_this" />
    <eForm ref="form" :sup_this="sup_this" />
    <!--表格渲染-->
    <DataGridTable
      v-loading="loading"
      ref="mainTable"
      :sup_this="sup_this"
      :data="data.rtnList"
      :total="total"
      @selection-change="handleGridSelectionChange">
      <el-table-column :show-overflow-tooltip="true" prop="jobName" width="100px" label="任务名称">
        <template slot-scope="scope">
          <edit :data="scope.row" :sup_this="sup_this" />
        </template>
      </el-table-column>
      <el-table-column :show-overflow-tooltip="true" prop="beanName" label="Bean名称"/>
      <el-table-column :show-overflow-tooltip="true" prop="methodParam" width="90px" label="参数"/>
      <el-table-column :show-overflow-tooltip="true" prop="cronExpression" width="130px" label="cron表达式"/>
      <el-table-column :show-overflow-tooltip="true" prop="running" width="90px" label="运行状态">
        <template slot-scope="scope">
          <el-tag :type="scope.row.running ? 'success' : 'warning'">{{ scope.row.running ? '正运行' : '待运行' }}</el-tag>
        </template>
      </el-table-column>
      <el-table-column :show-overflow-tooltip="true" prop="pause" width="90px" label="任务状态">
        <template slot-scope="scope">
          <el-tag :type="scope.row.pause ? 'warning' : 'success'">{{ scope.row.pause ? '已暂停' : '正常' }}</el-tag>
        </template>
      </el-table-column>
      <el-table-column :show-overflow-tooltip="true" prop="rmk" label="描述"/>
      <el-table-column :show-overflow-tooltip="true" prop="lastUpdateDate" label="更新日期">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.lastUpdateDate) }}</span>
        </template>
      </el-table-column>
      <el-table-column v-if="checkPermission(['SYS_ADMIN'])" label="操作" width="150px" align="center">
        <template slot-scope="scope">
          <el-button style="margin-left: -2px" type="text" size="mini" @click="runJob(scope.row.id)">执行</el-button>
          <el-button style="margin-left: 3px" type="text" size="mini" @click="pauseJob(scope.row.id)">
            {{ scope.row.pause ? '恢复' : '暂停' }}
          </el-button>
        </template>
      </el-table-column>
    </DataGridTable>
  </div>
</template>

<script>
import checkPermission from '@/utils/permission'
import initData from '@/mixins/initData'
import { loadDataUrl, doPauseJob, doRunJob } from '@/api/tools/job'
import { parseTime } from '@/utils/index'
import eHeader from './module/header'
import edit from './module/edit'
import eForm from './module/form'
export default {
  components: { eHeader, edit, eForm },
  mixins: [initData],
  data() {
    return {
      sup_this: this
    }
  },
  created() {
    this.url = loadDataUrl()
    this.$nextTick(() => {
      this.init()
    })
  },
  methods: {
    parseTime,
    checkPermission,
    async beforeInit() {
      return true
    },
    runJob(id) {
      doRunJob(id).then(res => {
        this.init()
      }).catch(err => {
        console.log(err)
      })
    },
    pauseJob(id) {
      doPauseJob(id).then(res => {
        this.init()
      }).catch(err => {
        console.log(err)
      })
    }
  }
}
</script>

<style scoped>

</style>
